package com.example.framework.util;

import com.example.framework.interfaces.AlertDialogBtnClickListenerInterface.OnPositiveButtonClickListener;
import com.example.framework.interfaces.AlertDialogBtnClickListenerInterface.OnThreeButtonClickListener;
import com.example.framework.interfaces.AlertDialogBtnClickListenerInterface.OnYesIgnoreButtonClickListener;
import com.example.framework.interfaces.AlertDialogBtnClickListenerInterface.OnYesNoButtonClickListener;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnKeyListener;
import android.view.KeyEvent;

/**
 * 
 * @author renxin.sun
 *
 */
public class UtilOfDialog
{
	public static AlertDialog alertDialogShow(Context context, Builder builder, int titleId, int messageId)
	{
		builder.setTitle(titleId);
		builder.setMessage(messageId);
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, int titleId, int messageId, int positiveBtnTextId, final OnPositiveButtonClickListener listener)
	{
		builder.setTitle(titleId);
		builder.setMessage(messageId);
		builder.setPositiveButton(positiveBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder,int titleId, int messageId, int positiveBtnTextId, int negativeBtnTextId, final OnYesNoButtonClickListener listener)
	{
		builder.setTitle(titleId);
		builder.setMessage(messageId);
		builder.setPositiveButton(positiveBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		builder.setNegativeButton(negativeBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNegativeButtonClick();
			}
		});
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, int titleId, int messageId, int positiveBtnTextId, int neutralBtnTextId, final OnYesIgnoreButtonClickListener listener)
	{
		builder.setTitle(titleId);
		builder.setMessage(messageId);
		builder.setPositiveButton(positiveBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		builder.setNeutralButton(neutralBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNeutralButtonClick();
			}
		});
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, int titleId, int messageId, int positiveBtnTextId, int negativeBtnTextId, int neutralBtnTextId, final OnThreeButtonClickListener listener)
	{
		builder.setTitle(titleId);
		builder.setMessage(messageId);
		builder.setPositiveButton(positiveBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		builder.setNegativeButton(negativeBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNegativeButtonClick();
			}
		});
		builder.setNeutralButton(neutralBtnTextId, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNeutralButtonClick();
			}
		});
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, CharSequence title, CharSequence message)
	{
		builder.setTitle(title);
		builder.setMessage(message);

		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, CharSequence title, CharSequence message, CharSequence positiveBtnText, final OnPositiveButtonClickListener listener)
	{
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton(positiveBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, CharSequence title, CharSequence message, CharSequence positiveBtnText, CharSequence negativeBtnText, final OnYesNoButtonClickListener listener)
	{
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton(positiveBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		builder.setNegativeButton(negativeBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNegativeButtonClick();
			}
		});
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, CharSequence title, CharSequence message, CharSequence positiveBtnText, CharSequence neutralBtnText, final OnYesIgnoreButtonClickListener listener)
	{
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton(positiveBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		builder.setNeutralButton(neutralBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNeutralButtonClick();
			}
		});
		return builder.create();
	}

	public static AlertDialog alertDialogShow(Context context, Builder builder, CharSequence title, CharSequence message, CharSequence positiveBtnText, CharSequence negativeBtnText, CharSequence neutralBtnText, final OnThreeButtonClickListener listener)
	{
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton(positiveBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnPositiveButtonClick();
			}
		});
		builder.setNegativeButton(negativeBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNegativeButtonClick();
			}
		});
		builder.setNeutralButton(neutralBtnText, new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				listener.OnNeutralButtonClick();
			}
		});
		return builder.create();
	}

	public static void dismissAlertDialog(AlertDialog alertDialog)
	{
		if (null != alertDialog)
		{
			alertDialog.dismiss();
		}
	}

	public static void showProgressDialog(Context context, final Dialog progressDialog)
	{
		progressDialog.setCancelable(false);
		progressDialog.setOnKeyListener(new OnKeyListener()
		{
			@Override
			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
			{
				if (KeyEvent.KEYCODE_BACK == keyCode)
				{
					progressDialog.dismiss();
					return true;
				}
				else
				{
					return false;
				}
			}
		});
		progressDialog.show();
	}

	public static void dismissProgressDialog(Dialog progressDialog)
	{
		if (null != progressDialog)
		{
			progressDialog.dismiss();
		}
	}
}
